package com.asset.dispoal.business.bsEvidenceRecognition.service.commom;

import com.asset.dispoal.business.bsEvidenceRecognition.dto.EvidenceMatchHistoryRequest;
import com.asset.dispoal.business.bsEvidenceRecognition.dto.IdCardRefreshHistoryResponse;
import com.asset.dispoal.business.idcardrefresh.domain.db.mapper.IdCardRefreshMapper;
import com.asset.dispoal.commom.page.PagingQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

@Component
@Slf4j
public class QueryIdCardRefreshPageCommand implements BaseCommand<EvidenceMatchHistoryRequest, Result<PageVO<IdCardRefreshHistoryResponse>>> {

    @Autowired
    IdCardRefreshMapper idCardRefreshMapper;

    @Override
    public Result<PageVO<IdCardRefreshHistoryResponse>> execute(EvidenceMatchHistoryRequest evidenceMatchHistoryRequest) {
        int count = idCardRefreshMapper.queryCountIdCardHistory(evidenceMatchHistoryRequest);
        Page<EvidenceMatchHistoryRequest> page = PagingQuery.getPage(count, evidenceMatchHistoryRequest);
        PageVO<IdCardRefreshHistoryResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<IdCardRefreshHistoryResponse> agreementDataResponses = idCardRefreshMapper.queryPageIdCardHistory(page);
            pageVO.setResult(agreementDataResponses);
        }
        return Result.ok(pageVO);
    }
}
